﻿using System;
using System.Windows.Forms;

namespace SQLServerSyncServer
{
    /**
     * 日志类
     */
    class Log
    {
        static DateTime dt;
        static string tableName;
        static string remark;

        public static void Message(ref ListView listView1, DateTime dt1, string Msg)
        {
            dt = dt1;
            tableName = "";

            remark = Msg;

            ListViewItem item = new ListViewItem();
            item.SubItems[0].Text = dt.ToString();
            item.SubItems.Add(tableName);
            item.SubItems.Add(remark);

            listView1.Items.Insert(0, item);
            ClearLog(ref listView1);
        }
        public static void Message(ref ListView listView1, DateTime dt1, string Msg, string tbName)
        {
            dt = dt1;
            tableName = tbName;
            remark = Msg;

            ListViewItem item = new ListViewItem();
            item.SubItems[0].Text = dt.ToString();
            item.SubItems.Add(tableName);
            item.SubItems.Add(remark);

            listView1.Items.Insert(0, item);
            ClearLog(ref listView1);
        }

        static void ClearLog(ref ListView lv)
        {
            if (lv.Items.Count >= 1000)
            {
                for (int i = 100; i < lv.Items.Count; i++)
                    lv.Items.RemoveAt(i);
            }
        }
    }
}
